package com.uhu.code;

/**
 * 11. 盛最多水的容器
 * https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-100-liked
 */
public class Solution11 {
    public int maxArea(int[] height) {
        int maxResult = minInt(height[0], height[1]);
        int i = 0, j = height.length - 1;
        while (i < j) {
            if (height[i] > height[j]) {
                int tempArea = height[j] * (j - i);
                maxResult = maxInt(tempArea, maxResult);
                j--;
            } else {
                int tempArea = height[i] * (j - i);
                maxResult = maxInt(tempArea, maxResult);
                i++;
            }
        }
        return maxResult;
    }

    private int minInt(int a, int b) {
        if (a > b) {
            return b;
        } else {
            return a;
        }
    }

    private int maxInt(int a, int b) {
        if (a > b) {
            return a;
        } else {
            return b;
        }
    }
}
